var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabdex: 'a1',
    tabs: [{
        tit: "简介",
        ids: "a1"
      },
      {
        tit: "症状",
        ids: "a2"
      },
      {
        tit: "病因",
        ids: "a3"
      },
      {
        tit: "诊断",
        ids: "a4"
      },
      {
        tit: "治疗",
        ids: "a5"
      },
      {
        tit: "预防",
        ids: "a6"
      },
    ]
  },
  tablick(e) {
    var that = this;
    var titles = e.currentTarget.dataset.titles
    var id = e.currentTarget.dataset.id;
    that.getDetail(id);
    // if (id == 'a1') {
    //   that.setData({
    //     detail: that.data.info.detail
    //   })
    // } else if (id == 'a2') {
    //   that.setData({
    //     detail: that.data.info.symptom
    //   })
    // } else if (id == 'a3') {
    //   that.setData({
    //     detail: that.data.info.reason
    //   })
    // } else if (id == 'a4') {
    //   that.setData({
    //     detail: that.data.info.diagnosis
    //   })
    // } else if (id == 'a5') {
    //   that.setData({
    //     detail: that.data.info.symptom
    //   })
    // } else if (id == 'a6') {
    //   that.setData({
    //     detail: that.data.info.prevention
    //   })
    // }
    this.setData({
      tabdex: e.currentTarget.dataset.id,
      name: titles
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var ids = options.ids
    wx.setNavigationBarTitle({
      title: options.title,
    })
    var id = options.id
    that.setData({
      title: options.title,
      id: id
    })
    var tabs = this.data.tabs
    if (options.name != '更多信息') {
      for (var i = 0; i < tabs.length; i++) {
        if (tabs[i].tit == options.name) {
          this.setData({
            tabdex: tabs[i].ids
          })
          break;
        }
      }
      that.setData({
        name: options.name
      })
    }

    that.getDetail(ids);
  },
  getDetail: function (ids) {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/answer.tank_detail",
      data: {
        id: that.data.id
      },
      success: function (res) {

        if (ids == 'a1') {
          that.setData({
            detail: res.data.detail
          })
        } else if (ids == 'a2') {
          that.setData({
            detail: res.data.symptom
          })
        } else if (ids == 'a3') {
          that.setData({
            detail: res.data.reason
          })
        } else if (ids == 'a4') {
          that.setData({
            detail: res.data.diagnosis
          })
        } else if (ids == 'a5') {
          that.setData({
            detail: res.data.symptom
          })
        } else if (ids == 'a6') {
          that.setData({
            detail: res.data.prevention
          })
        } else if (ids == 'a7') {
          that.setData({
            detail: res.data.detail
          })
        }
        that.setData({
          info: res.data,
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})